<template>
  <div class="wrapper">
    <div class="contentWrapper">
      <div class="imageWrapper">
        <img :src="product.small_image" alt />
      </div>
      <div class="infoWrapper">
        <div class="title">{{ product.name }}</div>
        <div class="priceWrapperItem">
          <div class="priceWrapper">{{ product.price | moneyFormat}}</div>
          <div class="originPrice">{{ product.origin_price | moneyFormat}}</div>
          <div class="cartWrapper glyphicon glyphicon-shopping-cart" @click="addToCart(product)"></div>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import PubSub from "pubsub-js";

export default {
  name: "youlikeitem",
  props: {
    product: Object
  },

  data() {
    return {};
  },
  methods: {
    addToCart(goods) {
      // alert("gagaga");
      // 异步发生
      PubSub.publish("homeAddToCart", goods);
    }
  }
};
</script>


<style lang="less" scoped>
.wrapper {
  display: inline-block;
  width: 46%;

  // display: flex;
  // flex-wrap: wrap;
  // justify-content: space-between;

  // width: 99%;
  // float: left;

  .contentWrapper {
    display: inline-block;
    width: 100%;
    background-color: #fff;

    .imageWrapper {
      padding: 1rem;
      text-align: center;
      img {
        width: 100%;
      }
    }

    .infoWrapper {
      padding: 0 1rem;

      .title {
        height: 3rem;
        line-height: 1.5rem;
        white-space: pre-wrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }

      .priceWrapperItem {
        position: relative;
        display: flex;
        justify-content: space-between;
        margin: 1.5rem 0 1rem 0;

        .priceWrapper {
          color: #fe6263;
        }

        .originPrice {
          position: absolute;
          left: 4.8rem;
          color: #999;
          text-decoration: line-through;
        }
        .cartWrapper {
          position: absolute;
          top: -0.3rem;
          right: 0rem;
          background-color: #3cb963;
          padding: 0.5rem;
          border-radius: 50%;
          color: #fff;
        }
      }
    }
  }
}
</style>